

package com.kimo.shop.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kimo.shop.bean.model.SkuRetail;
import com.kimo.shop.common.annotation.SysLog;
import com.kimo.shop.common.util.PageParam;
import com.kimo.shop.service.SkuRetailService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 *
 *
 * @author kimo-taozhouchuan
 * @date 2020-08-27 18:02:40
 */
@RestController
@AllArgsConstructor
@RequestMapping("/multishop/skuRetail" )
public class SkuRetailController {

    private final SkuRetailService skuRetailService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param skuRetail
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<SkuRetail>> getSkuRetailPage(PageParam<SkuRetail> page, SkuRetail skuRetail) {
        return ResponseEntity.ok(skuRetailService.page(page, new LambdaQueryWrapper<SkuRetail>()));
    }


    /**
     * 通过id查询
     * @param skuRetailId id
     * @return 单个数据
     */
    @GetMapping("/info/{skuRetailId}" )
    public ResponseEntity<SkuRetail> getById(@PathVariable("skuRetailId") Long skuRetailId) {
        return ResponseEntity.ok(skuRetailService.getById(skuRetailId));
    }

    /**
     * 新增
     * @param skuRetail
     * @return 是否新增成功
     */
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('multishop:skuRetail:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid SkuRetail skuRetail) {
        return ResponseEntity.ok(skuRetailService.save(skuRetail));
    }

    /**
     * 修改
     * @param skuRetail
     * @return 是否修改成功
     */
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('multishop:skuRetail:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid SkuRetail skuRetail) {
        return ResponseEntity.ok(skuRetailService.updateById(skuRetail));
    }

    /**
     * 通过id删除
     * @param skuRetailId id
     * @return 是否删除成功
     */
    @SysLog("删除" )
    @DeleteMapping("/{skuRetailId}" )
    @PreAuthorize("@pms.hasPermission('multishop:skuRetail:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long skuRetailId) {
        return ResponseEntity.ok(skuRetailService.removeById(skuRetailId));
    }

}
